package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.Greedy;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/assign-cookies/
 * g 孩子们需求的cookie大小
 * s 我们有的cookie大小
 * <p>
 * 贪心思路, 为了maximize the number of your content children
 * 随意尽量 用尽量小的cookie, 优先满足要的小的child
 *
 * @author tzp
 * @since 2020/10/17
 */
public class LC455 implements Greedy {
    public int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int k = 0;
        for (int i = 0; i < s.length && k < g.length; i++) {
            if (s[i] >= g[k]) k++;
        }
        return k;
    }

    public static void main(String[] args) {
        System.out.println(new LC455().findContentChildren(new int[]{1, 2, 3}, new int[]{1, 3}));
        System.out.println(new LC455().findContentChildren(new int[]{1, 2, 3}, new int[]{1, 1, 1, 1}));
        System.out.println(new LC455().findContentChildren(new int[]{1, 2, 1}, new int[]{1, 1, 1, 1}));
    }
}
